#include<iostream>
using namespace std;
 
int ShortLu_tonggen(int a, int b)
{
	while (a != b)
	{
		if (a < b)    b /= 2;
		else          a /= 2;
	}
	return a;
}
 
int main()
{
	int n = 0;
	cin >> n;
	int a, b;
	for (int i = 0 ; i <n ; i ++)
	{
		cin >> a >> b;
		if (a > b) swap(a, b);
		long long num = ShortLu_tonggen(a, b);
		long long left = num;
		long long right = num;
		int leftcount = 0;
		int rightcount = 0;
		while (left < a)
		{
			left = left * 2 +1;
			leftcount++;
		}
		while (right < b)
		{
			right = right * 2 + 1;
			rightcount++;
		}
		cout << leftcount + rightcount << endl;
	}
	return 0;
}